home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------------------------
- // Game Controller Declarations
- //
- // by Philip McBride
- //
- //--------------------------------------------------------------------------------------------
-
- //--------------------------------------------------------------------------------------------
- // Includes
- //
-
- #include <QDOffscreen.h>
-
- #include <QD3D.h>
- #include <QD3DAcceleration.h>
- #include <QD3DCamera.h>
- #include <QD3DController.h>
- #include <QD3DDrawContext.h>
- #include <QD3DErrors.h>
- #include <QD3DGeometry.h>
- #include <QD3DGroup.h>
- #include <QD3DIO.h>
- #include <QD3DLight.h>
- #include <QD3DMath.h>
- #include <QD3DPick.h>
- #include <QD3DRenderer.h>
- #include <QD3DSet.h>
- #include <QD3DShader.h>
- #include <QD3DStorage.h>
- #include <QD3DString.h>
- #include <QD3DStyle.h>
- #include <QD3DTransform.h>
- #include <QD3DView.h>
-
-
- //--------------------------------------------------------------------------------------------
- // Defines and Constants
- //
-
- #define kGestaltTrap 0xA0AD
-
- // some 3D constants
- static const TQ3ColorARGB kMyAClearColor = {1.0,1.0,1.0, 1.0};
- static const Rect kMyBoundsRect = {42,4,282,324};
-
- static const TQ3Point3D kMyDefaultFrom = {0.0,0.0,1.0};
- static const TQ3Point3D kMyDefaultTo = {0.0,0.0,0.0};
- static const TQ3Vector3D kMyDefaultUp = {0.0,1.0,0.0};
- static const float kMyDefaultHither = 0.01;
- static const float kMyDefaultYon = 1000000.0;
-
- // Here are our hard coded movement factors. We tried to make these general
- // for any size model, but in the end they are really tuned for simple models.
- // Especially the rotation factors. What seems to help is to remove or at
- // least minimize the model dimension (maxDimension used in MyInitDeltaFactors)
- // used to multiply the ...RotFactor structure fields of the document. Some
- // experimentation is needed here.
- static const float kXRotFactorBase = 0.005;
- static const float kYRotFactorBase = 0.05;
- static const float kZRotFactorBase = 0.001;
- static const float kXMoveFactorBase = 0.01;
- static const float kYMoveFactorBase = 0.005;
- static const float kZMoveFactorBase = 0.01;
- static const float kControlFactorBase = 0.01;
-
-
- // Here are some hard coded keys -- yikes. Of course this is just to keep
- // things simple. You will want to replace this with a nice preference setup.
- // Further, when QuickDraw 3D has keyboard (and mouse) controllers, this should
- // all go through that mechanism. Note, use the char codes to the right instead
- // of the numbers if you are using the alternative MyDoKeyMove function in
- // GameControls.c that switches off the char theKey argument.
-
- enum {
- iRight = 7, //'x',
- iLeft = 6, //'z',
- iUp = 3, //'f',
- iDown = 9, //'v',
- iForward = 91, //'8',
- iBackward = 87, //'5',
- iPanRight = 88, //'6',
- iPanLeft = 86, //'4',
- iPanUp = 2, //'d',
- iPanDown = 8, //'c',
- iBankL = 89, //'7',
- iBankR = 92, //'9',
- iLeftArrow = 123, //'\34',
- iRightArrow = 124, //'\35',
- iDownArrow = 125, //'\37',
- iUpArrow = 126 //'\36'
- } ;
-
-
- //--------------------------------------------------------------------------------------------
- // Document Structure
- //
-
- // our document structure (we use one for each window (and thus model))
- typedef struct _DocumentRecord {
- CWindowPtr theWindow; // display window
- FSSpec theFileSpec; // input file & ref
- short fRefNum;
- TQ3GroupObject documentGroup; // main group for the document
- TQ3ViewObject theView; // the documents view object
- TQ3Object viewHints; // viewhints of the model
-
- TQ3ShaderObject illuminationShader ;
- TQ3InterpolationStyle currentInterpolation;
-
- float width;
- float height;
-
- TQ3Point3D cameraLocation;
- TQ3Point3D pointOfInterest;
- TQ3Vector3D xVector;
- TQ3Vector3D yVector; //up vector
- TQ3Vector3D zVector;
-
- // Delta Factors
- float xRotFactor;
- float yRotFactor;
- float zRotFactor;
- float xMoveFactor;
- float yMoveFactor;
- float zMoveFactor;
- float controlFactor;
-
- } DocumentRecord, *DocumentPtr, **DocumentHandle ;
-
-
- //--------------------------------------------------------------------------------------------
- // Function Prototypes (event handlers and functions)
- //
-
- // apple event handlers
- pascal OSErr MyAEHandleOAPP(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
- pascal OSErr MyAEHandleODOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
- pascal OSErr MyAEHandlePDOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
- pascal OSErr MyAEHandleQUIT(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
- pascal OSErr MyAEHandleDragRecv(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon) ;
-
- // function prototypes
- void MyInitDeltaFactors(DocumentPtr mydocument);
- void MyDoMouseMove(WindowPtr theWindow, EventRecord *theEvent);
- void MyDoKeyMove(WindowPtr theWindow, EventRecord *theEvent, char theKey);
- Boolean CheckKey(short keyCode);
-
-